package com.lijy.objectStream;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ObjectStreamTest {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Employee a = new Employee("A", 10);
        Manager b = new Manager("B", 20);
        b.setSecretary(a);
        Manager c = new Manager("C", 20);
        c.setSecretary(a);

        Employee[] staff = new Employee[3];
        staff[0] = a;
        staff[1] = b;
        staff[2] = c;

        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("employee.dat"));
        out.writeObject(staff);

        ObjectInputStream in = new ObjectInputStream(new FileInputStream("employee.dat"));
        Employee[] newStaff = (Employee[]) in.readObject();
        newStaff[1].raiseSalary(10);
        for (Employee e : newStaff) {
            System.out.println(e);
        }
    }
}
